let test = require('./a.js')

console.log('打印test：', test)  //{ x: 1, add: [Function: add] }

console.log(test.x);  // 1
console.log(test.add())  // 2
console.log(test.x);   // 1


// ----------------------------------上面代码等同于
console.log('----------------------------------------------------------------')
let xModule = (function (){
  let x = 1;
  function add() {
    x += 1;
    return x;
  }
  return { x, add };
})();
let xm = xModule;
console.log(xm.x);  // 1
console.log(xm.add());  // 2
console.log(xm.x);   // 1